﻿// -----------------------------------------------------------------------
// <copyright file="FactoryMaker.cs" company="Hewlett-Packard">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Ex3.Repository
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using FacebookWrapper.ObjectModel;

    /// <summary>
    /// Initializes the factory.
    /// </summary>
    public class FactoryMaker
    {
        private const string REPOSITORY_CONFIGURATION = "RepositoryType.dat";

        public static RepositoryFactory GetFactory(User i_LoggedinUser)
        {
            return new RepositoryFactory(i_LoggedinUser, getRepositoryType());
        }

        private static RepositoryType getRepositoryType()
        {
            RepositoryType type = RepositoryType.XML;
            if (File.Exists(REPOSITORY_CONFIGURATION))
            {
                using (FileStream stream = File.OpenRead(REPOSITORY_CONFIGURATION))
                {
                    StreamReader reader = new StreamReader(stream);
                    string fileType = reader.ReadLine();
                    switch (fileType)
                    {
                        case "XML":
                            {
                                type = RepositoryType.XML;
                                break;
                            }
                    }
                }
            }

            return type;
        }
    }
}
